package com.example.permission.dao;

import com.example.permission.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户持久接口
 */
public interface UserMapper extends BaseMapper<User>{
    /* 通过用户名查找用户*/
    @Select("select * from user where username = #{username}")
    User getUserName(String username);

    //通过用户id 查找 该用户的角色id
    @Select("select role_id from user_role where user_id = #{userId}")
    List<Integer> getRoleIdsByUserId(Integer userId);

    //添加roleid
    @Insert("insert into user_role(user_id,role_id) value(#{userId},#{roleId})")
    Integer addRoleIdByUserId(Integer userId, Integer roleId);

    //删除roleid
    @Delete("delete from user_role where role_id = #{roleId}")
    Integer removeRoleIdByUserId(Integer id, Integer roleId);

    @Delete("delete from user_role")
    Integer deleteAll();
}
